package com.longqin.wechat.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

public class MyObjectUtil {
	
	public static boolean isNotNull(String str) {
		return  null!=str && !str.isEmpty();
	}
	
	/**判断是否为整数
	 * @param str
	 * @return
	 */
	public static boolean isInteger(String str){
		Pattern pattern =Pattern.compile("^[-\\+]?[\\d]*$");
		return pattern.matcher(str).matches();
	}
	
	
	/**Integr值是否相等
	 * @param a
	 * @param b
	 * @return
	 */
	public static boolean isIntValue(Integer a,Integer b){
		int tempA= a==null?0:a.intValue();
		int tempB= b==null?0:b.intValue();
		if(tempA==tempB)return true;
		else return false;
	}
	
	/**是否存在b
	 * @param list
	 * @param b
	 * @return
	 */
	public static boolean isExitValue(List<Integer> list,Integer b){
		if(null!=list && list.size()>0){
			int tempB= b==null?0:b.intValue();
			return list.contains(tempB);
		}else return false;
	}
	
	/**
	 * 获取流水号
	 * 
	 * @return
	 */
	public static String getSerialNum() {

		try {

			SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
			String serialNum = padLeft(formatter.format(new Date()), 20, '0');
			return serialNum;

		} catch (Exception ex) {

		}
		return "00000000000000000001";
	}
	
	/**
     * @description 自定义类似C#的padLeft
     * @param src
     *            源字符串
     * @param len
     *            总长度
     * @param ch
     *            补充字符
	 * @return 
     * @return 目标字符串
     */
	public static String padLeft(String src, int len, char ch) {
        int diff = len - src.length();
        if (diff <= 0) {
            return src;
        }
        char[] charr = new char[len];
        System.arraycopy(src.toCharArray(), 0, charr, diff, src.length());
        for (int i = 0; i < diff; i++) {
            charr[i] = ch;
        }
        return new String(charr);
    }


}
  